package com.glodon.cloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.glodon.cloud.domain.User;
import com.glodon.cloud.fegin.rpc.UserServiceFegin;

@RestController
public class FeginController {
	
	@Autowired
	private UserServiceFegin userServiceFegin ;

	@GetMapping("/fegin/sayHello/{userId}")
	public String sayHello(@PathVariable String userId) throws Exception{
		
		 ObjectMapper mapper = new ObjectMapper();  
		 User user = mapper.readValue(userServiceFegin.getUserById(userId),  User.class);
		return "Fegin -> Hello " + user.getUsername();
	}
	
}
